package com.grad.why.studentsystem.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.grad.why.studentsystem.domain.Unknownfaces;
import com.grad.why.studentsystem.mapper.UnknownfacesMapper;
import com.grad.why.studentsystem.service.UnKnownFacesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.List;

@Component
@Service(interfaceClass = UnKnownFacesService.class)
public class UnknownFacesServiceImpl implements UnKnownFacesService {
    @Autowired
    private UnknownfacesMapper unknownfacesMapper;

    @Override
    public List<Unknownfaces> getUnknownFacesListByAdmin(int offset, int limit, String search) {
        try{
            return unknownfacesMapper.getUnknownFacesListByAdmin(offset,limit,search);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public long getUnknownFacesLengthByAdmin(String search) {
        try{
            return unknownfacesMapper.getUnknownFacesLengthByAdmin(search);
        }catch (Exception E){
            E.printStackTrace();
        }
        return 0;
    }

    @Override
    public List<Unknownfaces> getUnknownFacesListByTeacher(int offset, int limit, String search, int bindid) {
        try{
            return unknownfacesMapper.getUnknownFacesListByTeacher(offset,limit,search,bindid);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public long getUnknownFacesLengthByTeacher(String search, int bindid) {
        try{
            return unknownfacesMapper.getUnknownFacesLengthByTeacher(search,bindid);
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int deleteUnknownFaceInfoById(String id) {
        try{
            Unknownfaces unknownfaces = unknownfacesMapper.selectByPrimaryKey(id);
            String picPath = unknownfaces.getImgpath();
            picPath = picPath.replace("/UnknownFaces","D:/unknowsFaces");
            File file = new File(picPath);
            boolean flag = file.delete();
            if(flag){
                return unknownfacesMapper.deleteByPrimaryKey(id);
            }else{
                return 0;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int checkSidMatchCourseId(Integer formatterNum, int courseId) {
        try{
            return unknownfacesMapper.checkSidMatchCourseId(formatterNum,courseId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public Unknownfaces getUnknownFaceInfoById(String unknownfaceid) {
        try{
            return unknownfacesMapper.selectByPrimaryKey(unknownfaceid);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int updateInfoByEntity(Unknownfaces unknownfaces) {
        try{
            return unknownfacesMapper.updateByPrimaryKeySelective(unknownfaces);
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public List<Unknownfaces> getUnknownFacesListByOrgStudent(int offset, int limit, String search, int bindid) {
        try{
            return unknownfacesMapper.getUnknownFacesListByOrgStudent(offset,limit,search,bindid);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public long getUnknownFacesLengthByOrgStudent(String search, int bindid) {
        try{
            return unknownfacesMapper.getUnknownFacesLengthByOrgStudent(search,bindid);
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }
}
